<?php
namespace Index\Controller;

use Index\Controller\CommonController;
class AnswerController extends CommonController {
// 问题页面输入回复
   public function indexAction(){
       if(IS_POST){
           $qid = I('post.qid');
           $content = I('post.content');
           $create_time = time();
           $uid = $_SESSION['uid'];
           $model = M();
           $sql = "insert into answer(uid,qid,content,create_time) values('{$uid}','{$qid}','{$content}','{$create_time}')";
           $isSuccess = $model->execute($sql);
           if($isSuccess){
               $sql = "select t1.reply from question t1 inner join answer t2 on t1.id = t2.qid and t2.qid ='{$qid}'";

               $replyData = $model -> query($sql);
               $reply = $replyData[0]['reply'] + 1;
               $sql = "update question set reply ='$reply' where id='{$qid}' ";
               $model->execute($sql);
               $this->success('发表成功',U("Index/Question/show/id/{$qid}"),1);
           }


       }


   }



}